package com.sdkj.dspservice.modules.demand.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.sdkj.dspservice.common.base.dao.CrudDao;
import com.sdkj.dspservice.modules.demand.entity.DemandDetails;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 需求详情DAO接口
 * @author tm
 */
public interface DemandDetailsDao extends CrudDao<DemandDetails> {

    /**
     * 获取指定需求，最后流程段
     * @param demandId
     * @return
     */
    @Select({"select *,user_id as \"user.id\", demand_id as \"demand.id\", demand_status as \"demand.status\", demand_flow_status as \"demand.flowStatus\" from demand_details where flow_sort = (select max(flow_sort) from demand_details where demand_id = #{demandId}) and demand_id = #{demandId}"})
    DemandDetails getLastByDemandId(String demandId);

    /**
     * 关联查询
     * @param wrapper
     * @return
     */
    @Select({"select a.*,u.name as \"user.name\" from demand_details a " +
            "left join sys_user u on u.id = a.user_id " +
            "${ew.customSqlSegment}"})
    List<DemandDetails> listLink(@Param(Constants.WRAPPER) Wrapper<DemandDetails> wrapper);
}
